package com.dongbing.demo.modules.common.api;



import com.dongbing.demo.modules.common.enums.ResponseEnum;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * @author  MrDong
 * @create  2021/6/24 13:34
 * @desc    自定义返回值类型
 **/
@Data
//返回前端的实体类中如果某个字段为空的话那么就不返回这个字段了
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class ResponseVo<T> {

    private Integer status;

    private String msg;

    private T data;

    private  ResponseVo(Integer status, T data){

        this.status = status;
        this.data = data;
    }

    private ResponseVo(ResponseEnum responseEnum,T data){

        this.status = responseEnum.getCode();
        this.msg = responseEnum.getDesc();
        this.data = data;
    }


    public static <T> ResponseVo<T> success(T data){

        return new ResponseVo<T>(ResponseEnum.SUCCESS.getCode(),data);
    }

    public static <T> ResponseVo<T> succeed(T data){

        return new ResponseVo<T>(ResponseEnum.SUCCESS,data);
    }
}
